package com.chenye.design.single;

/**
 * @Auther:chenye
 * @Data:2018/7/23
 * @Description:
 */
public class Single {
    private static String singleName = "test single";
    public static Single getSingle(){
        return SingleInit.single;
    }
    private static final Single single = new Single();

    //静态class 对象加载，利用了类加载器的特性，同一时间只有一个线程能加载类对象
    private final static class SingleInit{
        static{
            System.err.println("inner static class");
            System.err.println(singleName+"  outClass");
        }
        private static final Single single = new Single();
    }

    public static void main(String[] args){
        System.err.println(Single.singleName);
//        Single.getSingle();
        Single.SingleInit singleInit1 = new SingleInit();
        Single.SingleInit singleInit2 = new SingleInit();
        System.err.println(singleInit1==singleInit2);
    }
}
